<template>
    <el-dialog
      v-model="centerDialogVisible"
      width="30%"
      align-center
      color="white"
      style="  
     background-color: #053a6d6e;
      border: 5px solid #a1bf39;;"
    >
      <h1 style="color:white">用户地址</h1>
      <el-input v-model="oldaddress" disabled style="margin-bottom: 5px;color: white;" />
      <el-form  method="post">
        <el-form-item>

            <el-input v-model="newaddress" placeholder="请填写你的新地址" style="margin-bottom: 15px;color: white;" onfocus="this.placeholder=''" onblur="this.placeholder='请填写你的新地址'"  />
        </el-form-item>
        <el-form-item>
 <el-button type="success" round @click="changeadress()"
      @keyup.enter="changeadress()" class="tijiao">提交</el-button>

        </el-form-item>
     
    </el-form>
    </el-dialog>
 
  </template>
    <script>
 
  export default {
    name: "ChangeAddress",
  
    data() {
      return {
        centerDialogVisible: false,
        oldaddress:'',
        userId:'',
        newaddress:''
        
      };
    },
    created: function () {
      this.userName = sessionStorage.getItem("userName");
      console.log(this.userName);
      this.userId = sessionStorage.getItem("userId");
      console.log(this.userId);
    },
  
    methods: {
        finduseraddress(){
            this.userId=sessionStorage.getItem('userId')
            var data=new FormData()
            data.append('userid',this.userId)
            this.$axios.post('/finduseraddress',data).then(resp=>{
                this.oldaddress="旧地址："+resp.data
            })
        },
        changeadress(){
            this.userId=sessionStorage.getItem('userId')
           
           
            var data=new FormData()
            data.append('newaddress',this.newaddress) 
            data.append('userid',this.userId)
            this.$axios.post('/changeadress',data).then(resp=>{
                this.$message({
          message: "修改成功",
          type: "success",
        });
        this.centerDialogVisible=false
        this.finduseraddress()
     
        this.newaddress=''
            })
        }
      
    },
  
    mounted: function () {
    this.finduseraddress()
    },
  };
  </script>
    <style scoped>
  </style>